import java.util.*;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;

class LRUCache {
    HashMap<Integer, Integer> map;

    LinkedList<Integer> deque;

    int size;

    public LRUCache(int  size) {
        this.size = size;
        map = new HashMap<>();
        deque = new LinkedList<>();

    }


    public void put(int key, int value) {
        if ( !map.containsKey(key)) {
            if (deque.size() == this.size) {
                Integer removeKey = deque.removeLast();
                map.remove(removeKey);
                deque.offerFirst(key);
                map.put(key, value);
            }
            else {
                map.put(key, value);
                deque.offerFirst(key);
            }
        }
        else {
            map.put(key, value);
            deque.remove(key);
            deque.offerFirst(key);
        }

    }
    public int get(int key) {
        if ( !map.containsKey(key)) {
            return -1;
        }
        deque.remove(key);
        deque.offerFirst(key);
        return map.get(key);
    }


}
public class Main {

    public static void main(String[] args) {
        System.out.println("hello world");
        Integer[] a = new Integer[] {5,2,3,6,4,9,0};
        Integer[] b = new Integer[] {4,0,3};

        sortTest(a, b);

        System.out.println(Arrays.toString(a));
    }

    public static void sortTest(Integer[] a, Integer[] b) {
         
        HashMap<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < b.length; i++) {
            map.put(b[i], i);
        }

        Arrays.sort(a, (o1, o2) -> {
            if ( !map.containsKey(o1) && !map.containsKey(o2)) {
                return 0;
            }

            else if (map.containsKey(o1) && map.containsKey(o2)) {
                return map.get(o1) - map.get(o2);
            }

            else {
                if (!map.containsKey(o1)) {
                    return map.get(o2) - o1;
                } else {
                    return o2 - map.get(o1);
                }
            }

        });
    }


}







